$(document).ready(function ()
{
	//Maximizar y minimizar del panel inferior
	$("#btn-small-detail-module").click(function ()
	{
		$("#detail-module").removeClass("mid-size full-size");
	}
	);

	$("#btn-mid-detail-module").click(function ()
	{
		$("#detail-module").removeClass("full-size");
		$("#detail-module").addClass("mid-size");
	}
	);

	$("#btn-full-detail-module").click(function ()
	{
		$("#detail-module").removeClass("mid-size");
		$("#detail-module").addClass("full-size");
	}
	);


$("#cmbStatesTracking").kendoComboBox(
	{
		dataTextField : "text",
		dataValueField : "value",
		dataSource : [
			{
				text : "Pending Confirmation",
				value : "Pending Confirmation"
			},
			{
				text : "Pending Delivery",
				value : "Pending Delivery"
			},
			{
				text : "Committed",
				value : "Committed"
			},
			{
				text : "Close",
				value : "Close"
			}
		],
		value : "Pending Confirmation"
	}
	);


	//tab de lineas
	$("#lineTab").kendoTabStrip(
	{
		animation :
		{
			open :
			{
				effects : "fadeIn"
			}
		}
	}
	);

	$(".date-picker").kendoDatePicker();

	//navegacion del tab de detalles
	$("#subnav_tab a").click(function ()
	{
		$(".subnav > .active").removeClass("active");

		$(this).parent().addClass("active");

		//Muestro el divContent correspondiente
		var divContent = $(this).attr("divContent");

		$("#contentTab .divContent").hide();
		$("#" + divContent).show();

	}
	);


	var dataInfo = [
		{
			"Id" : 30,
			"Name" : "Linea 1",
			"Description" : "Linea de proyecto Uno",
			"Area" : "Construccion",
			"Pep" : "",
			"PR" : "1",
			"MaterialGroup" : "Material Group 1",
			"Plant" : null,
			"Company" : "",
			"Discount" : 0,
			"Budget" : 0,
			"Currency" : "",
			"Leader" : "\\SIDERCA\\T32606",
			"Project" : "Project Cuatro",
			"PepProject" : "",
			"Owner" : "\\SIDERCA\\T33333",
			"Criticity" : "Low",
			"State" : "Sourcing"
		},
		{
			"Id" : 64,
			"Name" : "1",
			"Description" : "",
			"Area" : "Construccion",
			"Pep" : "1",
			"PR" : "0",
			"MaterialGroup" : "Material Group 1",
			"Plant" : null,
			"Company" : "",
			"Discount" : 0,
			"Budget" : 0,
			"Currency" : "",
			"Leader" : "\\",
			"Project" : "Test 2",
			"PepProject" : "1",
			"Owner" : "\\SIDERCA\\T33333",
			"Criticity" : "",
			"State" : "Sourcing"
		},
		{
			"Id" : 61,
			"Name" : "1",
			"Description" : "1",
			"Area" : "Construccion",
			"Pep" : "1",
			"PR" : "0",
			"MaterialGroup" : "Material Group 1",
			"Plant" : null,
			"Company" : "",
			"Discount" : 1,
			"Budget" : 1,
			"Currency" : "",
			"Leader" : "\\",
			"Project" : "pro 2",
			"PepProject" : "1",
			"Owner" : "\\SIDERCA\\T33333",
			"Criticity" : "",
			"State" : "Sourcing"
		},
		{
			"Id" : 65,
			"Name" : "1",
			"Description" : "1",
			"Area" : "Construccion",
			"Pep" : "1",
			"PR" : "0",
			"MaterialGroup" : "Material Group 1",
			"Plant" : null,
			"Company" : "",
			"Discount" : 1,
			"Budget" : 0,
			"Currency" : "11",
			"Leader" : "\\",
			"Project" : "Test 3",
			"PepProject" : "1",
			"Owner" : "\\SIDERCA\\T33333",
			"Criticity" : "",
			"State" : "Sourcing"
		},
		{
			"Id" : 1,
			"Name" : "Compra de cemento",
			"Description" : "Se realizara la compra de cemento para el prabajo de pavimentacion.",
			"Area" : "Construccion",
			"Pep" : "1000.2",
			"PR" : "0",
			"MaterialGroup" : "Material Group 1",
			"Plant" : null,
			"Company" : "",
			"Discount" : 0,
			"Budget" : 0,
			"Currency" : "",
			"Leader" : "\\TERRIUM\\T33333",
			"Project" : "Pavimentacion",
			"PepProject" : "",
			"Owner" : "\\SIDERCA\\T33333",
			"Criticity" : "Low",
			"State" : "Sourcing"
		}
	];

	$("#ProjectTrackingGrid").kendoGrid(
	{
		dataSource :
		{
			type : "json",
			data : dataInfo,
			schema :
			{
				model :
				{
					fields :
					{
						Id :
						{
							type : "number"
						}
					}
				}
			},
			group :
			{
				field : "Project"
			}
		},
		sortable :
		{
			mode : "multiple"
		},
		height : 300,
		columns : [
			{
				field : "Project",
				title : "Project"
			},
			{
				field : "Description",
				title : "Description Project"
			},
			{
				field : "Name",
				title : "Line Project"
			},
			{
				field : "Owner",
				title : "Owner"
			},
			{
				field : "State",
				title : "State"
			}
		]
	}
	);

	var dataInfoPRs = [
		{
			"PR" : 12345,
			"Description" : "PR Description",
			"CreationDate" : "1/1/2014"
		}
	];

	$("#linePurchaseRequestsGrid").kendoGrid(
	{
		dataSource :
		{
			type : "json",
			data : dataInfoPRs,
			schema :
			{
				model :
				{
					fields :
					{
						Id :
						{
							type : "number"
						}
					}
				}
			}
		},
		sortable :
		{
			mode : "multiple"
		},
		height : 50,
		columns : [
			{
				field : "PR",
				title : "PR Number"
			},
			{
				field : "Description",
				title : "Description"
			},
			{
				field : "CreationDate",
				title : "Creation Date"
			}
		]
	}
	);

	var dataInfoSuppliers = [
		{
			"Name" : "BUSTIN SOLUCIONES INDUSTRIALES S.A.",
			"Country" : "AR",
			"ContactName" : "RAUL BUSTIN",
			"ContactMail" : "ventas@bustin.com.ar",
			"SupplierCodeExiros" : "0000050369",
			"SupplierCodeTenaris" : "0000110181",
			"SupplierCodeTernium" : "0000113858",
			"SupplierCodeTEIC" : "",
			"SupplierCodeSHREVEPORT" : "",
			"SupplierCodeTPI" : "",
			"SupplierCodeSiderar" : "0000113858",
			"SupplierCodeTEICExiros" : "0000103220",
			"SupplierCodeFerrasa" : "",
			"PerformanceRR" : "0.1",
			"PerformancePP" : "92",
			"PerformanceScoring" : "96"
		}
	];

	$("#commentsGrid").kendoGrid(
	{
		dataSource :
		{
			type : "json",
			data : dataInfoSuppliers,
			schema :
			{
				model :
				{
					fields :
					{
						Id :
						{
							type : "number"
						}
					}
				}
			}
		},
		sortable :
		{
			mode : "multiple"
		},
		height : 300,
		columns : [
			{
				field : "Name",
				title : "Commment"
			},
			{
				field : "Country",
				title : "Country"
			},
			{
				field : "ContactName",
				title : "Contact Name"
			},
			{
				field : "ContactMail",
				title : "Contact Mail"
			},
			{
				field : "SupplierCodeFerrasa",
				title : "Comments Description"
			}
		]
	}
	);

	var dataInfoSuppliersSearch = [
		{
			"Name" : "BUSTIN SOLUCIONES INDUSTRIALES S.A.",
			"Country" : "AR",
			"ContactName" : "RAUL BUSTIN",
			"ContactMail" : "ventas@bustin.com.ar",
			"SupplierCodeExiros" : "0000050369",
			"SupplierCodeTenaris" : "0000110181",
			"SupplierCodeTernium" : "0000113858",
			"SupplierCodeTEIC" : "",
			"SupplierCodeSHREVEPORT" : "",
			"SupplierCodeTPI" : "",
			"SupplierCodeSiderar" : "0000113858",
			"SupplierCodeTEICExiros" : "0000103220",
			"SupplierCodeFerrasa" : "",
			"PerformanceRR" : "0.1",
			"PerformancePP" : "92",
			"PerformanceScoring" : "96"
		}
	];

	$("#lineSuppliersSearchGrid").kendoGrid(
	{
		dataSource :
		{
			type : "json",
			data : dataInfoSuppliersSearch,
			schema :
			{
				model :
				{
					fields :
					{
						Id :
						{
							type : "number"
						}
					}
				}
			}
		},
		sortable :
		{
			mode : "multiple"
		},
		height : 300,
		columns : [
			{
				field : "Name",
				title : "Name"
			},
			{
				field : "Country",
				title : "Country"
			},
			{
				field : "ContactName",
				title : "Contact Name"
			},
			{
				field : "ContactMail",
				title : "Contact Mail"
			},
			{
				field : "SupplierCodeExiros",
				title : "Supplier Code Exiros"
			},
			{
				field : "SupplierCodeTenaris",
				title : "Supplier Code Tenaris"
			},
			{
				field : "SupplierCodeTernium",
				title : "Supplier Code Ternium"
			},
			{
				field : "SupplierCodeTEIC",
				title : "Supplier Code TEIC"
			},
			{
				field : "SupplierCodeSHREVEPORT",
				title : "Supplier Code SHREVEPORT"
			},
			{
				field : "SupplierCodeTPI",
				title : "Supplier Code TPI"
			},
			{
				field : "SupplierCodeSiderar",
				title : "Supplier Code Siderar"
			},
			{
				field : "SupplierCodeTEICExiros",
				title : "Supplier Code TEIC-Exiros"
			},
			{
				field : "SupplierCodeFerrasa",
				title : "Supplier Code Ferrasa"
			},
			{
				field : "PerformanceRR",
				title : "Performance RR"
			},
			{
				field : "PerformancePP",
				title : "Performance PP"
			},
			{
				field : "PerformanceScoring",
				title : "Performance Scoring"
			}
		]
	}
	);

	//Inicializo los divs de Contents
	$("#contentTab .divContent").hide();
	$("#lineDetailsContent").show();

	//Inicializo controles
	$("#cmbOwner").kendoComboBox(
	{
		dataTextField : "text",
		dataValueField : "value",
		dataSource : [
			{
				text : "Julian Pirola",
				value : "1"
			}
		],
		value : "1"
	}
	);

	
	
	$("#cmbDJAI").kendoComboBox(
	{
		dataTextField : "text",
		dataValueField : "value",
		dataSource : [
			{
				text : "Yes",
				value : "1"
			},
			{
				text : "NO",
				value : "2"
			},
			{
				text : "Not applicable",
				value : "3"
			}
		],
		value : "2"
	}
	);
	
	
	

	$("#cmbMaterialGroup").kendoComboBox(
	{
		dataTextField : "text",
		dataValueField : "value",
		dataSource : [
			{
				text : "TRANSFORMERS EQUIPMENT",
				value : "MIEA020"
			},
			{
				text : "MEASURING DEVICES/EQUIPMENT",
				value : "MIEA030"
			},
			{
				text : "DETECTION AND CONTROLLING DEVICES/EQUIPMENT",
				value : "MIEA040"
			},
			{
				text : "INDUCTION FURNACES EQUIPMENT ",
				value : "MIEA050"
			},
			{
				text : "DRIVES AND MOTORS EQUIPMENT",
				value : "MIEA060"
			},
			{
				text : "ELECTRICAL SUBSTATIONS EQUIPMENT",
				value : "MIEA070"
			},
			{
				text : "GENERATORS EQUIPMENT",
				value : "MIEA090"
			}
		],
		value : "MIEA050"
	}
	);

	$("#cmbCompany").kendoComboBox(
	{
		dataTextField : "text",
		dataValueField : "value",
		dataSource : [
			{
				text : "TECHINT S.A. DE C.V.",
				value : "01MX"
			},
			{
				text : "TECHINT SACI (TEARG)",
				value : "AR02"
			},
			{
				text : "TECHINT CHILE S.A.",
				value : "CL02"
			}
		],
		value : "AR02"
	}
	);

	$("#cmbPlant").kendoComboBox(
	{
		dataTextField : "text",
		dataValueField : "value",
		dataSource : [
			{
				text : "Algoma Seamless Tubular",
				value : "ALGO"
			},
			{
				text : "Algoma Steel Warehouse",
				value : "A050"
			},
			{
				text : "Campina Finished goods",
				value : "SN12"
			},
			{
				text : "Centro Acopio Bogota",
				value : "2150"
			}
		],
		value : "SN12"
	}
	);

	$("#cmbArea").kendoComboBox(
	{
		dataTextField : "text",
		dataValueField : "value",
		dataSource : [
			{
				text : "Terminacion y ajuste produccion",
				value : "3"
			},
			{
				text : "Servicios Industriales mantenimiento",
				value : "10"
			}
		],
		value : "10"
	}
	);

	//campos de montos
	$("#ntxtAmount").kendoNumericTextBox(
	{
		format: "$ #.00 US",
		decimals : 2,
		value : 500000,
		step : 0.50
	}
	).data("kendoNumericTextBox");
		
	

	$("#ntxtTotalAmount").kendoNumericTextBox(
	{
		format: "$ #.00 ",
		decimals : 2,
		value : 2,
		step : 0.50
	}
	).data("kendoNumericTextBox");
	
		
		

	//Oculta las flechas del numeric textbox
	($("#ntxtAmount").data("kendoNumericTextBox")).wrapper.find(".k-numeric-wrap").addClass("expand-padding").find(".k-select").hide();




	//Progress bar
	$("#pgbProject").kendoProgressBar(
	{
		type : "percent",
		value : 50
	}
	);

	//grilla del log
	$("#lineLogGrid").kendoGrid(
	{
		dataSource :
		{
			type : "json",
			data : [
				{
					"Comments" : null,
					"SimpleData" : null,
					"ObjectType" : null,
					"Object_" : null,
					"SubjectType" : "PROJECT",
					"Subject" : "Gruas proyecto laminador",
					"Action" : "INSERT",
					"Date" : "\/Date(1398717939000)\/",
					"User" : "SIDERCA\\13533"
				},
				{
					"Comments" : "Se compro porque se le ocurrio a un gerente",
					"SimpleData" : null,
					"ObjectType" : "LINE",
					"Object_" : "Grua 275 toneladas",
					"SubjectType" : "PROJECT",
					"Subject" : "Gruas proyecto laminador",
					"Action" : "INSERT",
					"Date" : "\/Date(1398717939000)\/",
					"User" : "SIDERCA\\13533"
				}
			],
			schema :
			{
				model :
				{
					fields :
					{
						Date :
						{
							type : "date"
						}
					}
				}
			},
		},
		height : 300,
		resizable : true,
		columns : [
			{
				field : "Date",
				title : "Date",
				format : "{0:dd/MM/yyyy}",
				width : 70
			},
			{
				field : "User",
				title : "User",
				width : 115
			},
			{
				field : "Action",
				title : "Action",
				width : 125
			},
			{
				field : "Subject",
				title : "Subject",
				width : 160
			},
			{
				field : "SubjectType",
				title : "SubjectType",
				width : 85
			},
			{
				field : "Object_",
				title : "Object",
				width : 130
			},
			{
				field : "ObjectType",
				title : "ObjectType",
				width : 80
			},
			{
				field : "Comments",
				title : "Comments",
				width : 255
			}
		]
	}
	);


	$("#btnSave").click(function ()
	{
		var notification = $("#notification").data("kendoNotification");

		notification.show(
		{
			message : "Project Saved"
		}, "save-success");

		$("#detail-module").removeClass("mid-size full-size");
	}
	);

	$("#addLine").click(function ()
	{
		var notification = $("#notification").data("kendoNotification");

		notification.show(
		{
			title : "Error creating new line",
			message : "PK violated"
		}, "error");
	}
	);

	$("#btnPRAdd").click(function () {
			var window = $("#winAddPR");

			window.show().kendoWindow({
				width: "950px",
				modal: true,
				title: "Add PR",
				resizable: false
			});

			window.data("kendoWindow").center();
			window.data("kendoWindow").open();
		}
	);

	$("#btnWinPRCancel").click(function() {
			var window = $("#winAddPR");

			window.data("kendoWindow").close();
		}
	);

	$("#btnSuppliersAdd").click(function () {
			var window = $("#winAddSuppliers");

			window.show().kendoWindow({
				width: "650px",
				modal: true,
				title: "Add Suppliers",
				resizable: false
			});

			window.data("kendoWindow").center();
			window.data("kendoWindow").open();
		}
	);

	$("#btnWinSuppliersCancel").click(function() {
			var window = $("#winAddSuppliers");

			window.data("kendoWindow").close();
		}
	);

	$("#btnLineSave").click(function () {
			var window = $("#winAddComment");

			window.show().kendoWindow({
				width: "490px",
				height: "150px",
				modal: true,
				title: "Add Comment",
				resizable: false
			});

			window.data("kendoWindow").center();
			window.data("kendoWindow").open();
		}
	);

		$("#btnWinCommentCancel").click(function() {
				var window = $("#winAddComment");

				window.data("kendoWindow").close();
			}
		);
	
		$(".switchYesNo").kendoMobileSwitch({
            onLabel: "YES",
            offLabel: "NO"
        });
		
		$("#switchDownpayment").kendoMobileSwitch({
            onLabel: "PAID",
            offLabel: "UNPAID"
        });
			
		 $(".switchLetterCredict").kendoMobileSwitch({
            onLabel: "OPEN",
            offLabel: "PEDING"
        });

}
);


